#!/usr/bin/env python
#coding: iso-8859-1

"""Documentation for camera.py

Contain the camera class, manages 
everything related to camer movement

project -- Rez: The Clone
author -- Edwood Grant
organization -- Binhex Tw. 
version -- 1.00
since -- 7/07/2007 12:31:50
"""

#Default imports
from math import pi, sin
#To handle actors
from direct.actor import Actor
from pandac.PandaModules import *
#To handle intervals
from direct.interval.IntervalGlobal import * 
import globals
import keyb

class Camera:
    def __init__(self):        
        self.resetCamera()
        #self.camTask2 = taskMgr.add(self.move, 'move')
        self.camTask2 = taskMgr.doMethodLater(1.2,self.move, 'move')

    def resetCamera(self):
        """Reset camera function
        
        Resets the camera postition, 
        if theres an actor to follow of course
        """
        #Standard variables
        self.min_dist = 1.5
        self.dist = -5
        self.max_dist = 85.0
        self.ang_cam_z = 36.0
        self.offset_z = 0.0
        self.ang_cam_x = 0
        self.ang_cam_y = 0
        self.inout = 0


    def move(self, task):
        if (globals.KEYBOARD_DEBUG.keyMap["cam-left"]!=0):
            self.ang_cam_y += 2.0
        if (globals.KEYBOARD_DEBUG.keyMap["cam-right"]!=0):
            self.ang_cam_y -= 2.0
        if (globals.KEYBOARD_DEBUG.keyMap["cam-up"]!=0):
            self.ang_cam_z += 2.0
        if (globals.KEYBOARD_DEBUG.keyMap["cam-down"]!=0):
            self.ang_cam_z -= 2.0
        if (globals.KEYBOARD_DEBUG.keyMap["cam-in"]!=0):
            self.inout += 1.0
        if (globals.KEYBOARD_DEBUG.keyMap["cam-out"]!=0):
            self.inout -= 1.0
        #print globals.PlayerPosition, camera.getPos()
        #seq = LerpPosInterval(camera,globalClock.getDt()*10,Vec3(-250+self.ang_cam_y, self.inout+(globals.PlayerPosition.getY()*0.25), self.ang_cam_z+(globals.PlayerPosition.getZ()*0.5)))
        #seq.start()
        #camera.setFluidPos(Vec3(-250+self.ang_cam_y, self.inout, self.ang_cam_z+(globals.PlayerPosition.getZ()*0.5)))

        #camera.setFluidPos(
        #    Vec3(-250+self.ang_cam_y,
        #         self.inout+(globals.PlayerPosition.getY()),
        #         self.ang_cam_z+globals.PlayerPosition.getZ())
        #    )
        camera.setPos(Vec3(-200+self.ang_cam_y,self.inout,self.ang_cam_z))
        camera.lookAt(10,0,0)
        #base.camLens.setFocalLength(0.5)
#       print camera.getPos()

        #camera.lookAt(globals.PlayerPosition+Vec3(10, 0, 0))
        self.camTask2 = taskMgr.doMethodLater(0.0,self.move, 'move')
        return task.done
